package 练习;

import java.util.concurrent.*;

public class ThreadTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3));
        Callable<String> callable = new Callable<>() {
            @Override
            public String call() throws Exception {
                for (int i = 0; i < 200; i++) {
                    System.out.println(Thread.currentThread().toString() + i);
                    TimeUnit.SECONDS.sleep(2);
                }
                return Thread.currentThread()+"完成";
            }
        };
        for (int i = 0; i < 7; i++) {
            threadPoolExecutor.submit(callable);
        }
    }
}
